#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

setup_sources = [
    '.coveragerc',
    '.stestr.conf',
    'MANIFEST.in',
    'README.md',
    'requirements.txt',
    'setup.py',
    'setup.cfg',
    'test-requirements.txt',
    'tox.ini',
    'vnc_cfg_api_server',
]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/config/api-server/" + file))

sandesh_trace_pkg = env.SandeshGenPy(
    'traces.sandesh', 'vnc_cfg_api_server/sandesh/', False)

sdist_depends = setup_sources_rules + sandesh_trace_pkg
cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_gen = env.Command('dist/contrail-api-server-0.1dev.tar.gz', 'setup.py',
                        cd_cmd + 'python setup.py sdist')

env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

# Documentation
doc_files = []
doc_files += env.SandeshGenDoc('traces.sandesh')
doc_files += env['CFGM_DOC_FILES']

if 'install' in BUILD_TARGETS:
    install_cmd = env.Command(None, 'setup.py',
                              cd_cmd + 'python setup.py install %s' %
                              env['PYTHON_INSTALL_OPT'])
    env.Depends(install_cmd, sdist_gen)
    env.Alias('install', install_cmd)

env.Alias('install', env.Install(env['INSTALL_CONF'], 'contrail-api.conf'))
env.Alias('install', env.InstallAs(env['INSTALL_INITD'] +
    '/contrail-api', 'contrail-api.initd.supervisord'))
env.Alias('install', env.InstallAs(env['INSTALL_SYSTEMD'] +
    '/contrail-api.service', 'systemd/contrail-api.service'))
env.Alias('install', env.Install(env['INSTALL_CONF'],
    'supervisord_config.conf'))
env.Alias('install', env.Install(env['INSTALL_CONF']+
    '/supervisord_config_files', 'contrail-api.ini'))
env.Alias('install', env.Install(env['INSTALL_CONF']+
    '/supervisord_config_files', 'contrail-config.rules'))
env.Alias('install', env.Install(
    env['INSTALL_MESSAGE_DOC'] + '/contrail-api/', doc_files))

env.SetupPyTestSuite(sdist_gen, use_tox=True)
